﻿@page
@model Moonglade.Web.Pages.IndexModel

@{
    ViewBag.TitlePrefix = null;
    ViewBag.ActionName = "Index";
}

<h3 class="d-flex">
    <span>
        @SharedLocalizer["All Posts"]
    </span>
    
    <span class="flex-spacer"></span>
    
    <span class="me-1">
        <select class="form-select form-select-sm" asp-for="SortBy" id="sort-selection" title="Selection box for sort post list by recent or featured">
            <option value="Recent">Recent</option>
            <option value="Featured">Featured</option>
        </select>
    </span>
    
    <a class="d-none d-md-block" asp-controller="Subscription" asp-action="Rss" target="_blank" title="@SharedLocalizer["Subscribe recent posts"]">
        <i class="bi-rss font-125rem"></i>
    </a>
</h3>
<hr />

@if (Model.Posts.Any())
{
    <partial name="_PostList" model="Model.Posts" />
}
else
{
    <div class="alert alert-info">
        @SharedLocalizer["No Posts"]
    </div>
}

<partial name="_LightSwitch" />

@section scripts{
    <script>
        var sortSelect = document.getElementById("sort-selection");
        sortSelect.addEventListener("change", function () {
            var value = sortSelect.value;
            var searchParams = new URLSearchParams(window.location.search);
            searchParams.set("sortBy", value);
            window.location.search = searchParams.toString();
        });
    </script>
}